package com.openbravo.pos.config;

import com.openbravo.data.user.DirtyManager;
import com.openbravo.pos.forms.AppConfig;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.util.AltEncrypter;
import com.openbravo.pos.util.DirectoryEvent;

import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.text.Document;

public class JPanelConfigDatabase extends JPanel
  implements PanelConfig
{
  private DirtyManager dirty = new DirtyManager();
  private JLabel jLabel1;
  private JLabel jLabel18;
  private JLabel jLabel2;
  private JLabel jLabel3;
  private JLabel jLabel4;
  private JPanel jPanel1;
  private JButton jbtnDbDriverLib;
  private JTextField jtxtDbDriver;
  private JTextField jtxtDbDriverLib;
  private JPasswordField jtxtDbPassword;
  private JTextField jtxtDbURL;
  private JTextField jtxtDbUser;

  public JPanelConfigDatabase()
  {
    initComponents();
    this.jtxtDbDriverLib.getDocument().addDocumentListener(this.dirty);
    this.jtxtDbDriver.getDocument().addDocumentListener(this.dirty);
    this.jtxtDbURL.getDocument().addDocumentListener(this.dirty);
    this.jtxtDbPassword.getDocument().addDocumentListener(this.dirty);
    this.jtxtDbUser.getDocument().addDocumentListener(this.dirty);
    this.jbtnDbDriverLib.addActionListener(new DirectoryEvent(this.jtxtDbDriverLib));
  }

  public boolean hasChanged()
  {
    return this.dirty.isDirty();
  }

  public Component getConfigComponent()
  {
    return this;
  }

  public void loadProperties(AppConfig paramAppConfig)
  {
    this.jtxtDbDriverLib.setText(paramAppConfig.getProperty("db.driverlib"));
    this.jtxtDbDriver.setText(paramAppConfig.getProperty("db.driver"));
    this.jtxtDbURL.setText(paramAppConfig.getProperty("db.URL"));
    String str1 = paramAppConfig.getProperty("db.user");
    String str2 = paramAppConfig.getProperty("db.password");
    if ((str1 != null) && (str2 != null) && (str2.startsWith("crypt:")))
    {
      AltEncrypter localAltEncrypter = new AltEncrypter("cypherkey" + str1);
      str2 = localAltEncrypter.decrypt(str2.substring(6));
    }
    this.jtxtDbUser.setText(str1);
    this.jtxtDbPassword.setText(str2);
    this.dirty.setDirty(false);
  }

  public void saveProperties(AppConfig paramAppConfig)
  {
    paramAppConfig.setProperty("db.driverlib", this.jtxtDbDriverLib.getText());
    paramAppConfig.setProperty("db.driver", this.jtxtDbDriver.getText());
    paramAppConfig.setProperty("db.URL", this.jtxtDbURL.getText());
    paramAppConfig.setProperty("db.user", this.jtxtDbUser.getText());
    AltEncrypter localAltEncrypter = new AltEncrypter("cypherkey" + this.jtxtDbUser.getText());
    paramAppConfig.setProperty("db.password", "crypt:" + localAltEncrypter.encrypt(new String(this.jtxtDbPassword.getPassword())));
    this.dirty.setDirty(false);
  }

  private void initComponents()
  {
    this.jPanel1 = new JPanel();
    this.jLabel18 = new JLabel();
    this.jtxtDbDriverLib = new JTextField();
    this.jbtnDbDriverLib = new JButton();
    this.jLabel1 = new JLabel();
    this.jtxtDbDriver = new JTextField();
    this.jLabel2 = new JLabel();
    this.jtxtDbURL = new JTextField();
    this.jLabel3 = new JLabel();
    this.jtxtDbUser = new JTextField();
    this.jLabel4 = new JLabel();
    this.jtxtDbPassword = new JPasswordField();
    this.jPanel1.setBorder(BorderFactory.createTitledBorder(AppLocal.getIntString("Label.Database")));
    this.jLabel18.setText(AppLocal.getIntString("label.dbdriverlib"));
    this.jbtnDbDriverLib.setIcon(new ImageIcon(getClass().getResource("/com/openbravo/images/fileopen.png")));
    this.jLabel1.setText(AppLocal.getIntString("Label.DbDriver"));
    this.jLabel2.setText(AppLocal.getIntString("Label.DbURL"));
    this.jLabel3.setText(AppLocal.getIntString("Label.DbUser"));
    this.jLabel4.setText(AppLocal.getIntString("Label.DbPassword"));
    GroupLayout localGroupLayout1 = new GroupLayout(this.jPanel1);
    this.jPanel1.setLayout(localGroupLayout1);
    localGroupLayout1.setHorizontalGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout1.createSequentialGroup().addContainerGap().addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(this.jLabel18, -2, 130, -2).addComponent(this.jLabel1).addComponent(this.jLabel2).addComponent(this.jLabel3).addComponent(this.jLabel4)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout1.createSequentialGroup().addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.LEADING, false).addComponent(this.jtxtDbURL, -2, 328, -2).addComponent(this.jtxtDbDriverLib, -2, 328, -2).addComponent(this.jtxtDbDriver, -2, 165, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(this.jbtnDbDriverLib)).addComponent(this.jtxtDbPassword, -2, 165, -2).addComponent(this.jtxtDbUser, -2, 165, -2)).addContainerGap(131, 32767)));
    localGroupLayout1.setVerticalGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout1.createSequentialGroup().addContainerGap().addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout1.createSequentialGroup().addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel18).addComponent(this.jtxtDbDriverLib, -2, -1, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel1).addComponent(this.jtxtDbDriver, -2, -1, -2))).addComponent(this.jbtnDbDriverLib)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel2).addComponent(this.jtxtDbURL, -2, -1, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel3).addComponent(this.jtxtDbUser, -2, -1, -2)).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addGroup(localGroupLayout1.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(this.jLabel4).addComponent(this.jtxtDbPassword, -2, -1, -2)).addContainerGap(14, 32767)));
    GroupLayout localGroupLayout2 = new GroupLayout(this);
    setLayout(localGroupLayout2);
    localGroupLayout2.setHorizontalGroup(localGroupLayout2.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout2.createSequentialGroup().addContainerGap().addComponent(this.jPanel1, -1, -1, 32767).addContainerGap()));
    localGroupLayout2.setVerticalGroup(localGroupLayout2.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(localGroupLayout2.createSequentialGroup().addContainerGap().addComponent(this.jPanel1, -2, -1, -2).addContainerGap(14, 32767)));
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.config.JPanelConfigDatabase
 * JD-Core Version:    0.6.0
 */